﻿using Xejen.Communication.Http.Configuration;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;

namespace Xejen.Communication.Http.Abstract
{
    /// <summary>
    /// 表示Json传输的<see langword="ContentType"/>内容策略
    /// </summary>
    /// <creator>marc</creator>
    internal class JsonContentStrategy : ContentStrategyBase, IHttpContentStrategy
    {
        /// <inheritdoc cref="JsonContentStrategy"/>
        /// <param name="config"><inheritdoc/></param>
        public JsonContentStrategy(HttpConfig config) : base(config) { }

        /// <inheritdoc/>
        public override HttpContent CreateHttpContent(object data)
        {
            //string contentType = HttpConfig.ContentType;
            string contentType = "application/json";

            //var content = new StringContent(JsonSerializer.Serialize(data, HttpConfig.JsonSerializerOptions), HttpConfig.Encoding);
            var content = new StringContent(data.ToString(), HttpConfig.Encoding);
            content.Headers.ContentType = new MediaTypeHeaderValue(contentType);
            return content;
        }
    }
}
